﻿<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>SOSOMap_TestMap</title>
<style type="text/css">
body, button, input, select, textarea {
font: 12px/16px Verdana, Helvetica, Arial, sans-serif;
}
</style>
<script charset="utf-8" src="http://api.map.soso.com/v1.0/main.js"></script>
<script>
//地图初始化
function init() {
	map = new soso.maps.Map(document.getElementById("container"), {
		// 地图的中心地理坐标。
		center: new soso.maps.LatLng(39.916527,116.397128),
		zoomLevel:13
	});
	marker = null;
	geocoder = new soso.maps.Geocoder();
	codeLatLng();
}
//地址解析
function codeAddress() {
	var address = document.getElementById("address").value;
	geocoder.geocode({'address': address}, function(results, status){
		if (status == soso.maps.GeocoderStatus.OK) {
			map.moveTo(results.location);
			if (marker != null) {
				marker.setMap(null);
			}
			marker = new soso.maps.Marker({
				map: map,
				position:results.location
			});
		}
		else{
			alert("检索没有结果，原因: " + status);
		}
	});
}
//反地址解析
function codeLatLng(){
	soso.maps.Event.addListener(map, 'click', function(e){
		var latLng = e.latLng;
		var info = new soso.maps.InfoWindow({map: map});
		geocoder.geocode({'location': latLng}, function(results, status){
			if (status == soso.maps.GeocoderStatus.OK) {
				info.open('<div style="width:280px;height:100px;">'+results.address+'</div>', latLng);
			}
			else{
				alert("检索没有结果，原因: " + status);
			}
		});
	});
}
</script>
</head>
<body onload="init();">
<div style="width:650px;height:400px" id="container"></div> 
<div>      
<input id="address" type="textbox" style='width:300px' value="中国,北京,海淀区,海淀大街38号">
<input type="button" value="search" onclick="codeAddress()">
</div> 
</body>
</html>